package com.rsk.service.impl;

import com.rsk.dao.SysCompanyResponsiblesRepository;
import com.rsk.entity.SysCompanyResponsibles;
import com.rsk.service.SysCompanyResponsiblesService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

public class SysCompanyResponsiblesServiceImpl implements SysCompanyResponsiblesService {

    @Autowired
    SysCompanyResponsiblesRepository sysCompanyResponsiblesRepository;

    /**
     * 删除机构负责人
     * @param id
     * @param operatorUser
     * @return
     */
    @Transactional
    @Override
    public int delSysCompanyResponsible(Long id, Long operatorUser) {
        return sysCompanyResponsiblesRepository.delSysSysCompanyResponsibles(id,operatorUser);
    }

    /**
     * 修改机构负责人
     * @param id
     * @param companyId
     * @param responsibleName
     * @param responsiblePhone
     * @param responsiblePost
     * @param operatorUser
     * @return
     */
    @Transactional
    @Override
    public int updateSysCompanysResponsible(Long id, String companyId, String responsibleName, String responsiblePhone,String responsiblePost,Long operatorUser) {
        return sysCompanyResponsiblesRepository.updateSysSysCompanyResponsibles(id,companyId,responsibleName,responsiblePhone,responsiblePost,operatorUser);
    }

    /**
     * 新增机构负责人
     * @param id
     * @param companyId
     * @param responsibleName
     * @param responsiblePhone
     * @param responsiblePost
     * @param remarks
     * @param mainResponsiable
     * @param operatorUser
     * @return
     */
    @Transactional
    @Override
    public int saveSysCompanysResponsible(Long id, Long companyId, String responsibleName, String responsiblePhone, String responsiblePost, Long remarks,int mainResponsiable, Long operatorUser) {

        SysCompanyResponsibles companyResponsibles = new SysCompanyResponsibles();
        companyResponsibles.setId(SnowflakeIdWorker.generateId(true));
        companyResponsibles.setCompanyId(companyId);
        companyResponsibles.setResponsibleName(responsibleName);
        companyResponsibles.setResponsiblesPhone(responsiblePhone);
        companyResponsibles.setResponsiblePost(responsiblePost);
        companyResponsibles.setRemarks(remarks);
        companyResponsibles.setMainResponsible(mainResponsiable);
        companyResponsibles.setOperatorUser(operatorUser);
        sysCompanyResponsiblesRepository.saveAndFlush(companyResponsibles);
        return 1;
    }

}
